package com.kstudio.videocapture.listfile;

import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;

import com.kstudio.videocapture.R;

public class KFileListAdapterWrapper {
    private View    		mBase;
    private KFileListItem   mItem;
    private int     		mPostion;

    private KFileListViewSubIcon           mIcon;
    private TextView                       mName;
    private TextView                       mDuration;
    private ImageButton		               mCheckNo;
    private ImageButton	 		           mCheckYes;
    private KFileListCheckClickListener    mListener;

    public interface KFileListCheckClickListener {
        public void onFileCheckClick(boolean b);
    }

    public KFileListAdapterWrapper(View base, KFileListCheckClickListener l) {
        this.mBase = base;
        this.mPostion = 0;
        this.mListener = l;

        this.mIcon = null;
        this.mName = null;
        this.mDuration = null;
        this.mCheckNo = null;
        this.mCheckYes = null;
    }

    public String getPath() {
        return mItem.getPath();
    }

    public int getPosition() {
        return mPostion;
    }

    public boolean getChecked() {
        return mItem.getFileCheck();
    }

    public KFileListViewSubIcon getIcon() {
        if(mIcon == null) {
            mIcon = (KFileListViewSubIcon)mBase.findViewById(R.id.filelist_row_icon);
        }
        return mIcon;
    }

    public TextView getName() {
        if(mName == null) {
            mName = (TextView)mBase.findViewById(R.id.filelist_row_name);
        }
        return mName;
    }

    public TextView getDuration() {
        if(mDuration == null) {
            mDuration = (TextView)mBase.findViewById(R.id.filelist_row_duration);
        }
        return mDuration;
    }

    public ImageButton getCheckNo() {
        if(mCheckNo == null) {
        	mCheckNo = (ImageButton)mBase.findViewById(R.id.filelist_row_no_check);
        	mCheckNo.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					Log.e("KKH","mCheckNo OnClickListener");
					mItem.setFileCheck(true);
					mCheckNo.setVisibility(View.GONE);
					mCheckYes.setVisibility(View.VISIBLE);
					if(mListener != null) mListener.onFileCheckClick(true);
				}
			});
        }
        return mCheckNo;
    }

    public ImageButton getCheckYes() {
        if(mCheckYes == null) {
        	mCheckYes = (ImageButton)mBase.findViewById(R.id.filelist_row_yes_check);
        	mCheckYes.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Log.e("KKH","mCheckYes OnClickListener");
                    mItem.setFileCheck(false);
                    mCheckNo.setVisibility(View.VISIBLE);
                    mCheckYes.setVisibility(View.GONE);
                    if(mListener != null) mListener.onFileCheckClick(false);
                }
            });
        }
        return mCheckYes;
    }

    public void setItem(KFileListItem item) {
        mItem = item;
    }

    public void setPosition(int position) {
        mPostion = position;
    }
 }
